//
//  ROFoodDetailTableViewController.swift
//  neufood
//
//  Created by huangminmin on 2017/10/26.
//  Copyright © 2017年 huangminmin. All rights reserved.
//

import UIKit

class ROFoodDetailTableViewController: UITableViewController {
    var food:ROFoodModel!

    override func viewDidLoad() {
        self.title=food.foodname as String
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       
        return 3
    }

    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       var basecell:UITableViewCell=UITableViewCell()
        if (indexPath as NSIndexPath).row == 0 {
            let cell : ROFoodHeaderCell = tableView.dequeueReusableCell(withIdentifier: "foodHeaderCell", for: indexPath) as! ROFoodHeaderCell
            cell.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: CELLHEIGHT);
            
            tableView.separatorStyle = UITableViewCellSeparatorStyle.none;
            
            let imageStr = food.pic
            let imageURL = URL(string: imageStr as! String)
            cell.foodImageView!.setImageWith(imageURL!, placeholderImage: UIImage(named: "placeHolder"))
            
            //菜品名称
            cell.foodName.text = "\(food.foodname!)"
            //菜品价格
            cell.price.text = "\(food.price!)元"
            //推荐指数
            cell.recommand.text = "\(food.recommand!)"
            //商店编号
            cell.shop_id.text = "\(food.shop_id!)"
            basecell = cell
            
        }
        else if((indexPath as NSIndexPath).row == 1){
            let cell: RoFoodIntroduceCell = tableView.dequeueReusableCell(withIdentifier: "foodIntrCell", for: indexPath) as! RoFoodIntroduceCell
            //先设置模型
            cell.food = food;
            //再算Cell的frame
            cell.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: RoFoodIntroduceCell.cellHeightWithPostinModel(food));
            basecell = cell;
       }
        else if((indexPath as NSIndexPath).row == 2) {
            let cell = foodDetailCell.creatCell(tableView)
            cell.food = food
            basecell = cell
        }
       
   
       

        return basecell
    }
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        if ((indexPath as NSIndexPath).row == 0) {
            return CELLHEIGHT;
        }else if((indexPath as NSIndexPath).row == 1){
            //返回可变的cell高度 需要根据模型的内容进行计算
            // return ROCourseIntroduceCell.cellHeightWithPostinModel(food)
            return CELLHEIGHT;
            
        }else{
            return 60;
        }
    }
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 1 {
            return 40
        }else{
            return 0
        }
    }

    

}
